package gui.util;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JCheckBox;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeCellRenderer;

public class CheckboxTreeCellRenderer implements TreeCellRenderer {

	/**
	 * Because we know that all items in the list are in fact checkboxes, this
	 * will return the checkbox itself, after retyping it from the
	 * <code>Object</code>. This ensures that every checkbox in the list will
	 * get painted correctly. Background will be set to that of the underlying
	 * list, or light blue, if the current component is the seleceted one.
	 */


	@Override
	public Component getTreeCellRendererComponent(JTree tree, Object value,
			boolean sel, boolean expanded, boolean leaf, int row,
			boolean hasFocus) {
		
		Object userObject = ((DefaultMutableTreeNode)value).getUserObject();
		JCheckBox val = (JCheckBox)userObject;
		
		if (sel) {
			val.setBackground(new Color(127, 127, 255));
		}
		else {
			val.setBackground(tree.getBackground());
		}



		return val;
	}
}